package cn.tedu.warehouse.service.impl;

import cn.tedu.warehouse.entity.Check;
import cn.tedu.warehouse.entity.Result;
import cn.tedu.warehouse.mapper.CheckMapper;
import cn.tedu.warehouse.page.Page;
import cn.tedu.warehouse.service.CheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class CheckServiceImpl implements CheckService {
    @Autowired
    private CheckMapper checkMapper;

//分页查询盘点单业务方法
    @Override
    public Page queryCheckPage(Page page, Check check) {
        log.debug("分页查询盘点单业务：{}", check);

        //查询盘点单总行数
        int checkCount = checkMapper.selectCheckCount(check);
        //分页查询盘点单
        List<Check> checkList = checkMapper.selectCheckPage(page, check);
        //将查询到的总行数和当前页数数据组装到Page对象中Page对象
        page.setTotalNum(checkCount);
        page.setResultList(checkList);
        return page;
    }
//添加盘点单业务方法
    @Override
    public Result savecheck(Check check) {
        log.debug("添加盘点单业务：{}", check);
        //添加盘点单
        int i = checkMapper.savecheck(check);

        if (i> 0) {
            return Result.ok("添加盘点单成功");
        }
        return Result.err(Result.CODE_ERR_BUSINESS, "盘点单添加失败！");
    }
//修改盘点单业务方法
    @Override
    public Result updateCheck(Check check) {
        log.debug("修改盘点单业务：{}", check);
        int rows = checkMapper.updateCheck(check);
        if (rows > 0) {
            return Result.ok("盘点单修改成功");
        }
        return Result.err(Result.CODE_ERR_BUSINESS, "盘点单修改失败！");
    }


//删除业务
    @Override
    public Result deletecheck(Integer checkId) {
        log.debug("删除盘点单业务：{}", checkId);
        int rows = checkMapper.deleteCheck(checkId);
        if (rows > 0) {
            return Result.ok("盘点单删除成功");
        }
        return Result.err(Result.CODE_ERR_BUSINESS, "盘点单删除失败！");
    }
}
